home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / pcb-1.000 / pcb-1 / pcb-1.3 / set.c < prev    next >
C/C++ Source or Header  |  1995-02-27  |  8KB  |  311 lines

  1. /*
  2.  *                            COPYRIGHT
  3.  *
  4.  *  PCB, interactive printed circuit board design
  5.  *  Copyright (C) 1994,1995 Thomas Nau
  6.  *
  7.  *  This program is free software; you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation; either version 2 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  This program is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with this program; if not, write to the Free Software
  19.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  *
  21.  *  Contact addresses for paper mail and Email:
  22.  *  Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
  23.  *  Thomas.Nau@rz.uni-ulm.de
  24.  *
  25.  */
  26.  
  27. static    char    *rcsid = "$Header: set.c,v 2.1 94/09/28 14:27:03 nau Exp $";
  28.  
  29. /* routines to update widgets and global settings
  30.  * (except output window and dialogs)
  31.  */
  32.  
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36.  
  37. #include "global.h"
  38.  
  39. #include "buffer.h"
  40. #include "crosshair.h"
  41. #include "control.h"
  42. #include "data.h"
  43. #include "draw.h"
  44. #include "misc.h"
  45. #include "set.h"
  46.  
  47. #include <X11/cursorfont.h>
  48.  
  49. /* ---------------------------------------------------------------------------
  50.  * output of cursor position
  51.  */
  52. void SetCursorStatusLine(void)
  53. {
  54.     char    text[20];
  55.  
  56.     sprintf(text, "%-i,%-i", Crosshair.X, Crosshair.Y);
  57.     XtVaSetValues(Output.CursorPosition, XtNlabel, text, NULL);
  58. }
  59.  
  60. /* ---------------------------------------------------------------------------
  61.  * output of status line
  62.  */
  63. void SetStatusLine(void)
  64. {
  65.     char    text[100];
  66.     int        length;
  67.  
  68.     sprintf(text, "%c grid=%i%c%c, zoom=1:%-i, line=%-i, via=%-i(%-i), buffer=%-i, name: ",
  69.         PCB->Changed ? '*' : ' ', PCB->Grid,
  70.         TEST_FLAG(ABSOLUTEFLAG, PCB) ? 'a' : 'r',
  71.         TEST_FLAG(ALLDIRCETIONFLAG, PCB) ? 'a' : ' ',
  72.         (int) (TO_PCB(1)),
  73.         (int) Settings.LineThickness,
  74.         (int) Settings.ViaThickness, (int) Settings.ViaDrillingHole,
  75.         Settings.BufferNumber+1);
  76.  
  77.         /* append the name of the layout */
  78.     length = 79 -strlen(text);
  79.     strncat(text, UNKNOWN(PCB->Name), length);
  80.     text[79] = '\0';
  81.     XtVaSetValues(Output.StatusLine, XtNlabel, text, NULL);
  82. }
  83.  
  84. /* ---------------------------------------------------------------------------
  85.  * sets cursor grid with respect to grid offset values
  86.  */
  87. void SetGrid(int Grid)
  88. {
  89.     if (Grid >= 1 && Grid <= MAX_GRID)
  90.     {
  91.             /* set offset relative to current location or absolute
  92.              * to (0,0) depending on resource
  93.              * DrawGrid() uses XOR mode
  94.              */
  95.         if (Settings.DrawGrid)
  96.             DrawGrid();
  97.         PCB->GridOffsetX= TEST_FLAG(ABSOLUTEFLAG, PCB) ? 0 : Crosshair.X % Grid;
  98.         PCB->GridOffsetY= TEST_FLAG(ABSOLUTEFLAG, PCB) ? 0 : Crosshair.Y % Grid;
  99.         PCB->Grid = Grid;
  100.  
  101.             /* reset flag if density is too high */
  102.         if (Settings.DrawGrid && (TO_SCREEN(PCB->Grid) < MIN_GRID_DISTANCE))
  103.             Settings.DrawGrid = False;
  104.         if (Settings.DrawGrid)
  105.             DrawGrid();
  106.         SetStatusLine();
  107.     }
  108.  
  109. /* ---------------------------------------------------------------------------
  110. * sets new zoom factor, adapts size of viewport and centers the cursor
  111. */
  112. void SetZoom(int Zoom)
  113. {
  114.     Zoom = MAX(MIN_ZOOM, Zoom);
  115.     Zoom = MIN(MAX_ZOOM, Zoom);
  116.  
  117.         /* redraw only if zoom has changed */
  118.     if (PCB->Zoom != Zoom)
  119.     {
  120.             /* saved pixmap is invalid */
  121.         ReleaseSaveUnderPixmap();
  122.         PCB->Zoom = Zoom;
  123.  
  124.             /* recalculate size of viewport */
  125.         XtVaSetValues(Output.Output,
  126.             XtNwidth, TO_SCREEN(PCB->MaxWidth),
  127.             XtNheight, TO_SCREEN(PCB->MaxHeight),
  128.             NULL);
  129.  
  130.         CenterDisplay(TO_SCREEN_X(Crosshair.X), TO_SCREEN_Y(Crosshair.Y));
  131.     }
  132.         /* always redraw status line (used for init sequence) */
  133.     SetStatusLine();
  134.  
  135. /* ---------------------------------------------------------------------------
  136.  * sets a new line thickness
  137.  */
  138. void SetLineSize(Dimension Size)
  139. {
  140.     if (Size >= MIN_LINESIZE && Size <= MAX_LINESIZE)
  141.     {
  142.         Settings.LineThickness = Size;
  143.         SetStatusLine();
  144.     }
  145. }
  146.  
  147. /* ---------------------------------------------------------------------------
  148.  * sets a new via thickness
  149.  */
  150. void SetViaSize(Dimension Size)
  151. {
  152.     if (Size <= MAX_PINORVIASIZE &&
  153.         Size >= MIN_PINORVIASIZE &&
  154.         Size >= Settings.ViaDrillingHole +MIN_PINORVIACOPPER)
  155.     {
  156.         Settings.ViaThickness = Size;
  157.         SetStatusLine();
  158.     }
  159. }
  160.  
  161. /* ---------------------------------------------------------------------------
  162.  * sets a new via drilling hole
  163.  */
  164. void SetViaDrillingHole(Dimension Size)
  165. {
  166.     if (Size <= MAX_PINORVIASIZE &&
  167.         Size >= MIN_PINORVIAHOLE &&
  168.         Size <= Settings.ViaThickness -MIN_PINORVIACOPPER)
  169.     {
  170.         Settings.ViaDrillingHole = Size;
  171.         SetStatusLine();
  172.     }
  173. }
  174.  
  175. /* ---------------------------------------------------------------------------
  176.  * sets or resets changed flag and redraws status
  177.  */
  178. void SetChangedFlag(Boolean New)
  179. {
  180.         /* seems that the save output area is invalid now */
  181.     ReleaseSaveUnderPixmap();
  182.     PCB->Changed = New;
  183.     SetStatusLine();
  184. }
  185.  
  186. /* ---------------------------------------------------------------------------
  187.  * sets a new buffer number
  188.  */
  189. void SetBufferNumber(int Number)
  190. {
  191.     if (Number >= 0 && Number < MAX_BUFFER)
  192.     {
  193.         Settings.BufferNumber = Number;
  194.  
  195.             /* do an update on the crosshair range */
  196.         if (Settings.Mode == PASTEBUFFER_MODE)
  197.         {
  198.             SetBufferBoundingBox(PASTEBUFFER);
  199.             SetCrosshairRange(
  200.                 PASTEBUFFER->X -PASTEBUFFER->BoundingBox.X1,
  201.                 PASTEBUFFER->Y -PASTEBUFFER->BoundingBox.Y1,
  202.                 PCB->MaxWidth-
  203.                     (PASTEBUFFER->BoundingBox.X2 -PASTEBUFFER->X),
  204.                 PCB->MaxHeight-
  205.                     (PASTEBUFFER->BoundingBox.Y2 -PASTEBUFFER->Y));
  206.         }
  207.         SetStatusLine();
  208.     }
  209. }
  210.  
  211. /* ---------------------------------------------------------------------------
  212.  * updates all widgets like status, cursor position ... on screen
  213.  */
  214. void UpdateSettingsOnScreen(void)
  215. {
  216.     SetStatusLine();
  217.     SetCursorStatusLine();
  218.     UpdateControlPanel();
  219. }
  220.  
  221. /* ---------------------------------------------------------------------------
  222.  * set a new mode and update X cursor
  223.  */
  224. void SetMode(int Mode)
  225. {
  226.         /* protect the cursor while changing the mode
  227.          * perform some additional stuff depending on the new mode
  228.          * reset 'state' of attached objects
  229.          */
  230.     HideCrosshair(True);
  231.     Crosshair.AttachedBox.State = STATE_FIRST;
  232.     Crosshair.AttachedLine.State = STATE_FIRST;
  233.     Crosshair.AttachedObject.State = STATE_FIRST;
  234.     Crosshair.AttachedPolygon.PointN = 0;
  235.  
  236.         /* reset 'valid' cursor area to maximum;
  237.          * some modes force a change in the 'case' statement
  238.          */
  239.     SetCrosshairRange(0, 0, PCB->MaxWidth, PCB->MaxHeight);
  240.  
  241.     Settings.Mode = Mode;
  242.     switch(Mode)
  243.     {
  244.         case NO_MODE:
  245.             SetOutputXCursor(XC_crosshair);
  246.             break;
  247.  
  248.         case VIA_MODE:
  249.             SetOutputXCursor(XC_arrow);
  250.             break;
  251.  
  252.         case LINE_MODE:
  253.             Crosshair.AttachedLine.State = STATE_FIRST;
  254.             SetOutputXCursor(XC_pencil);
  255.             break;
  256.  
  257.         case POLYGON_MODE:
  258.             SetOutputXCursor(XC_sb_up_arrow);
  259.             break;
  260.  
  261.         case PASTEBUFFER_MODE:
  262.             SetOutputXCursor(XC_hand1);
  263.  
  264.                 /* do an update on the crosshair range */
  265.             SetBufferBoundingBox(PASTEBUFFER);
  266.             SetCrosshairRange(
  267.                 PASTEBUFFER->X -PASTEBUFFER->BoundingBox.X1,
  268.                 PASTEBUFFER->Y -PASTEBUFFER->BoundingBox.Y1,
  269.                 PCB->MaxWidth-
  270.                     (PASTEBUFFER->BoundingBox.X2 -PASTEBUFFER->X),
  271.                 PCB->MaxHeight-
  272.                     (PASTEBUFFER->BoundingBox.Y2 -PASTEBUFFER->Y));
  273.             break;
  274.  
  275.         case TEXT_MODE:
  276.             SetOutputXCursor(XC_xterm);
  277.             break;
  278.  
  279.         case RECTANGLE_MODE:
  280.             SetOutputXCursor(XC_ul_angle);
  281.             break;
  282.  
  283.         case REMOVE_MODE:
  284.             SetOutputXCursor(XC_pirate);
  285.             break;
  286.  
  287.         case MIRROR_MODE:
  288.             SetOutputXCursor(XC_sb_h_double_arrow);
  289.             break;
  290.  
  291.         case ROTATE_MODE:
  292.             SetOutputXCursor(XC_exchange);
  293.             break;
  294.  
  295.         case COPY_MODE:
  296.         case MOVE_MODE:
  297.             SetOutputXCursor(XC_crosshair);
  298.             break;
  299.     }
  300.     UpdateModeSelection();
  301.  
  302.         /* force a crosshair grid update because the valid range
  303.          * may have changed
  304.          */
  305.     MoveCrosshairRelative(0, 0);
  306.     RestoreCrosshair(True);
  307. }
  308.  
  309.